package com.rong.tools.exception;

import com.rong.tools.entity.vo.ResponseVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 周厚荣
 * @date 2025/4/21 21:32
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public ResponseVO<?> handleBusinessException(BusinessException e) {
        log.error(e.getMessage());
        return ResponseVO.getFailResponseVO(e.getCode(),e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public ResponseVO<?> handleAllException(Exception e) {
        log.error(e.getMessage());
        return ResponseVO.getFailResponseVO(e.getMessage());
    }

    // 你还可以根据不同异常定制方法 ↓↓↓
    @ExceptionHandler(IllegalArgumentException.class)
    public ResponseVO<?> handleIllegalArgument(IllegalArgumentException e) {
        log.error(e.getMessage());
        return ResponseVO.getFailResponseVO(400,e.getMessage());
    }
}

